#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>


int connect2Server(const char* ip, const unsigned short port){
	int csock;
	if((csock=socket(PF_INET,SOCK_STREAM,0))<0){
		perror("socket");
		return -1;
	}

	struct sockaddr_in addr;
	memset(&addr, 0, sizeof(addr));
	addr.sin_family=AF_INET;
	addr.sin_port=htons(port);
	addr.sin_addr.s_addr=inet_addr(ip);
	if(connect(csock,(struct sockaddr *)&addr, sizeof(addr))<0){
		perror("connect");
		close(csock);
		return -1;
	}
	return csock;
}
